import { Component } from '@angular/core';
import { ActivatedRoute} from '@angular/router';  
@Component({
  selector: 'app-menu',
  templateUrl: './menu.component.html',
  styleUrls: ['./menu.component.scss']
})
export class MenuComponent {
  id: any;
  music:any = {}
  song:any[] =[{}]
  data:any = ''
  image:string =''
  musicId:string =''
  showDelete:boolean = false
  constructor(private route: ActivatedRoute){
    // this.getSong()
    this.route.queryParamMap.subscribe((data)=>{
      this.musicId = ((data as any).params.id)
      this.getMusic()
    })
    }
  goBack():void{
    history.go(-1)
  }
  // 获取歌单
  async getMusic(){
   let url = "http://metapunk.cn:9999/parse/classes/Music?"
  //  获取 歌单的ID
   let paramsId;
   if(!this.musicId){
   }else{
    paramsId = `"objectId":"${this.musicId}"`
   }
   let paramsWhere
   paramsWhere = `where={${paramsId}}`
   url += "&" + paramsWhere
  // 包含 歌曲指针条件
  let paramsInclude = "include=song";
    url += "&" + paramsInclude

    console.log(url)
    let result = await fetch(url, {
      "headers": {
        "x-parse-application-id": "dev"
      },
      "body": null,
      "method": "GET",
      "mode": "cors",
      "credentials": "omit"
    });
    let data = await result.json()
    console.log(data)
    let dataMusic =  data.results
    dataMusic.map((item: any)=>{
      this.music = item
      // this.song = this.music.song
     })
  }
// 获取单曲
  // async getSong(){
  //   let response = await fetch("http://metapunk.cn:9999/parse/classes/Song", {
  //     "credentials": "omit",
  //     "headers": {
  //         "X-Parse-Application-Id": "dev",
  //     },
  //     "method": "GET",
  //     "mode": "cors"
  //   })
  //   let data = await response.json()
  //   this.song = data.results
  // }
}

